﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.Admin.DicClassManage
{
	public partial class AddDicClass : BasePage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (RightValidate())
			{
				if (!IsPostBack)
					Page.DataBind();
			}
		}

		protected void UCAddDicClass_Init(object sender, EventArgs e)
		{
			UCAddDicClass.SiteId = SiteId;
		}

		protected void BtSubmit_Click(object sender, EventArgs e)
		{
			if (RightValidate() && IsValid)
			{
				DicClass info = UCAddDicClass.Info;
				info.SiteId = SiteId;
				DicClasses.Insert(info);
				InsertComplete();
			}
		}

		/// <summary>
		/// 返回权限验证结果，如果验证失败则显示消息提示。
		/// </summary>
		/// <returns>布尔值代表权限验证是否通过。</returns>
		public bool RightValidate()
		{
			bool right = DicClasses.GetInsertRight(new DicClass { SiteId = SiteId });
			if (!right)
			{
				Messages.Add(new PageMessage(false, null, PageMessageType.Error, Res.PermissionExceptionMessageTitle, Res.PermissionExceptionMessage));
			}
			return right;
		}

		/// <summary>
		/// 插入操作完成，显示消息提示。
		/// </summary>
		public void InsertComplete()
		{
			Messages.Add(new PageMessage(true, null, PageMessageType.Prompt, Res.OperationCompleteTitle, Res.OperationComplete_Insert));
		}
	}
}
